package it.unicam.fishpass.prism.parser;

import java.util.ArrayList;

/**
 * @param <T>
 *            MDP node type
 * @param <K>
 *            MDP arc type
 * 
 * @author Andrea Baiocco
 */
public class MDPGraph<T, K> {

	ArrayList<T> Nodes;
	ArrayList<ArrayList<K>> arcs;

	MDPGraph() {
		Nodes = new ArrayList<T>();
		arcs = new ArrayList<ArrayList<K>>();
	}

	boolean addVertex(T vertex) {
		if (Nodes.contains(vertex))
			return false;
		Nodes.add(vertex);
		arcs.add(Nodes.size() - 1, new ArrayList<K>());
		return true;
	}

	boolean addMultiArc(T source, K arc) {
		ArrayList<K> marcs = arcs.get(Nodes.indexOf(source));
		for (K m : marcs)
			if (m.equals(arc))
				return false;
		// else the arc is NOT in the graph...addition!
		marcs.add(arc);
		return true;
	}

	boolean contains(String vertex) {
		return Nodes.contains(vertex);
	}
	
	int getVertexCount()
	{
		return Nodes.size();
	}
	
	int getArcsCount()
	{
		int count = 0;
		  for(ArrayList<K> arcx : arcs)
		   count+= arcx.size();
		  return count;
	}
	
	int getVertexIndex(String vertex)
	{
		return Nodes.indexOf(vertex);
	}
	
	ArrayList<K> getArcs(int index)
	{
		return arcs.get(index);
	}
	
}